(async () => {
    const options = {
        moduleCache: {vue: Vue},
        getFile(url) {
            return fetch(url).then(res => {
                if (!res.ok) throw Object.assign(new Error(url + ' ' + res.statusText), {res});
                return res.text();
            })
        },
        addStyle(textContent) {
            document.head.insertBefore(
                Object.assign(document.createElement('style'), {textContent}),
                document.head.getElementsByTagName('style')[0] || null);
        },
    };
    const {loadModule} = window['vue3-sfc-loader'];
    const loadVue = (vuePath) => loadModule(vuePath, options);
    const loadVueFile = (vuePath) => () => loadVue(vuePath);

    let routes = [
        /*首页*/
        {path: '/', component: loadVueFile('../views/index.vue')},
    ]
    const args = {name: 'root', components: {'layout': await loadVue('../views/layout.vue')}};
    const vueApp = Vue.createApp(args)
    vueApp.use(VueRouter.createRouter({history: VueRouter.createWebHashHistory(), routes: routes}))
    vueApp.mount("#root")
    window.vueApp=vueApp;
})().catch(ex => console.error(ex));
